package com.gitee.zeric.codec.myger;

import com.alibaba.fastjson.JSONObject;
import com.gitee.zeric.codec.generaters.AbstractCodeGerator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
/**
 * 自定义编码规则测试用例
 * 获取随机组合码
 * <br>字符型 LETTER,
 * <br>数字型 NUMBER,
 * <br>大+小字符型 LETTER_CAPITAL,
 * <br>小字符+数字 型 LETTER_NUMBER,
 * <br>大+小字符+数字 型 LETTER_CAPITAL_NUMBER,
 * <br>大+小字符+数字+符号 型 LETTER_CAPITAL_NUMBER_SIGN
 */

/**
 * @author zj
 * @date 2021/12/17
 */
public class PasswordGenerater extends AbstractCodeGerator {

    private static String[] lowercase = {
            "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
            "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};

    private static String[] capital = {
            "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
            "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};

    private static String[] number = {
            "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};

    private static String[] sign = {"!", "@", "#", "$", "^", "*", "(", ")", "_", "{", "}", "[", "]", ";", ",", "."};

    /**
     * 静态随机数
     */
    private static final Random random = new Random();

    /**
     * 获取随机组合码
     * <br>字符型 LETTER,
     * <br>数字型 NUMBER,
     * <br>大+小字符型 LETTER_CAPITAL,
     * <br>小字符+数字 型 LETTER_NUMBER,
     * <br>大+小字符+数字 型 LETTER_CAPITAL_NUMBER,
     * <br>大+小字符+数字+符号 型 LETTER_CAPITAL_NUMBER_SIGN
     */
    public static String getRandom(int num, String type) {
        ArrayList<String> temp = new ArrayList<String>();
        StringBuilder code = new StringBuilder();
        switch (type) {
            case "LETTER":
                temp.addAll(Arrays.asList(lowercase));
                break;
            case "NUMBER":
                temp.addAll(Arrays.asList(number));
                break;
            case "LETTER_CAPITAL":
                temp.addAll(Arrays.asList(lowercase));
                temp.addAll(Arrays.asList(capital));
                break;
            case "LETTER_NUMBER":
                temp.addAll(Arrays.asList(lowercase));
                temp.addAll(Arrays.asList(number));
                break;
            case "LETTER_CAPITAL_NUMBER":
                temp.addAll(Arrays.asList(lowercase));
                temp.addAll(Arrays.asList(capital));
                temp.addAll(Arrays.asList(number));
                break;
            default:
                temp.addAll(Arrays.asList(lowercase));
                temp.addAll(Arrays.asList(capital));
                temp.addAll(Arrays.asList(number));
                temp.addAll(Arrays.asList(sign));
        }
        for (int i = 0; i < num; i++) {
            code.append(temp.get(random.nextInt(temp.size())));
        }
        return code.toString();
    }
    @Override
    public String generate(String ruleCode,JSONObject jsonObject)  {
        return getRandom(16, "suiji");
    }

    @Override
    protected String[] fields() {
        return new String[]{};
    }
}
